package org.example.system.controller;


import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.example.system.entity.Employee;
import org.example.system.entity.User;
import org.example.system.service.AuthService;
import org.example.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 认证控制器
 */
@RestController
@RequestMapping("/app")
@Slf4j
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 用户登录
     * @param loginUser
     * @return
     */
    @PostMapping("/login")
    public R login(@RequestBody User loginUser){
        log.info("--------AuthController | login | input:{}", JSON.toJSONString(loginUser));
        if (StrUtil.isEmpty(loginUser.getUsername()) ||
        StrUtil.isEmpty(loginUser.getPassword())){
            return R.fail("参数错误");
        }
        Object token = authService.login(loginUser);
        return R.ok(token);
    }
}
